package com.xjj.servicejob.mapper;


import com.xjj.entity.Img;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author sjy
 * @create 2022-10-20 11:38
 * 发布作业图片Mapper
 */
public interface JobSubmitPhotoMapper {
    /**
     * 添加提交作业的图片
     * @param jobSubmitPhotos
     */
    @Insert({"<script>" +
            "insert into xjj_job_submit_photo(submit_id,url) values" +
            "<foreach collection='jobSubmitPhotos' item='img' separator=','>" +
            "(#{img.relationalId},#{img.url})" +
            "</foreach>" +
            "</script>"})
    void insert(@Param("jobSubmitPhotos") List<Img> jobSubmitPhotos);

    /**
     * 删除提交的作业的图片
     * @param ids
     * @param submitId
     */
    @Delete({"<script>" +
            "delete from xjj_job_submit_photo where id in" +
            "<foreach collection='ids' item='id'  open='('  separator=','  close=')'>" +
            "#{id}" +
            "</foreach>" +
            "and submit_id =#{submitId}" +
            "</script>"})
    void delete(@Param("ids") List<Integer> ids, @Param("submitId") Integer submitId);

    /**
     * 获取该提交作业的所有图片
     * @param submitId
     * @return
     */
    @Select("select * from xjj_job_submit_photo where submit_id =#{submitId}")
    @Results(
            id = "jobSubmitPhotoMapper",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "job_id", property = "relationalId"),
                    @Result(column = "url", property = "url")
            }
    )
    List<Img> getAllImgByJobId(Integer submitId);
}
